<template>
	<view class="vip_container">
		<view class="login_box">
			<view v-if="!memberInfo.isIdentityChecked">
				<view class="form_box">
					<text class="txt1">手&nbsp;&nbsp;机&nbsp;号：</text>
					<input type="text" placeholder-class="account-txt" :disabled="true" v-model="params.mobileNo" class="uni-input" placeholder="请输入您要绑定的新手机号码" />
				</view>
				<view class="form_box" v-if="!memberInfo.isPhoneChecked">
					<view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
						<text class="txt1">验&nbsp;&nbsp;证&nbsp;码：</text>
						<input type="number" placeholder-class="account-txt" v-model="params.smsCode" class="uni-input input_yzm" placeholder="验证码" />
						<button @click="getCode" :disabled="disabled" class="register_yzms">
			                {{countdown}} <text v-if="timestatus">秒重获</text>
			            </button>
					</view>
				</view>
			</view>
			<view v-if="!memberInfo.isIdentityChecked">
				<view class="form_box">
					<text class="txt1">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</text>
					<input type="text" placeholder-class="account-txt" v-model="params.name" class="uni-input" placeholder="请输入姓名" />
				</view>
				<view class="form_box">
					<text class="txt1">身&nbsp;&nbsp;份&nbsp;证：</text>
					<input type="text" placeholder-class="account-txt" v-model="params.idCard" class="uni-input" placeholder="请输入您要绑定的身份证" />
				</view>
			</view>
			<view v-if="memberInfo.isPhoneChecked && memberInfo.isIdentityChecked">
				<view class="form_box">
					<text class="txt1">手&nbsp;&nbsp;机&nbsp;号：</text>
					<input type="text" placeholder-class="account-txt" v-model="memberInfo.phone.substr(0, 3) + '****' + memberInfo.phone.substr(7)" class="uni-input" placeholder="请输入您要绑定的新手机号码" />
				</view>
				<view class="form_box">
					<text class="txt1">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</text>
					<input type="text" placeholder-class="account-txt" v-model="memberInfo.name" :disabled="true" class="uni-input" placeholder="请输入姓名" />
				</view>
				<view class="form_box">
					<text class="txt1">身&nbsp;&nbsp;份&nbsp;证：</text>
					<input type="text" placeholder-class="account-txt" v-model="memberInfo.identityCardNo.substr(0, 6) + '*******' + memberInfo.identityCardNo.substr(13)" :disabled="true" class="uni-input" placeholder="请输入您要绑定的身份证" />
				</view>
			</view>
			<view v-if="!memberInfo.isIdentityChecked" style="display: flex;justify-content: center;align-items: center;">
				<button type="primary" class="btn_pri" style="background-color: #477EDA;" @click="toRenZen">提交认证</button>
			</view>
		</view>
	</view>
</template>

<script>
	import { sendSmsCode, modifyStudentMobileNo } from '../../common/api/index.js';
	export default {
		data() {
			return {
				params: {
					mobileNo: uni.getStorageSync('s_mobile'),
					smsCode: '',
					name: '',
					idCard: ''
				},
				numberCode: 60,
				disabled: false,
				countdown:'获取验证码',
				timestatus:false,
				memberInfo: {}
			}
		},
		onShow:function(){
			this._getIndividualMemberInfo()
		},
		computed: {
			getSfz(str) {
				return function (str) {
					return str.replace(/^(.{6})(?:\w+)(.{4})$/, "\$1********\$2")
				}
			}
		},
		methods: {
			_getIndividualMemberInfo() {
				let bizUserId = uni.getStorageSync('bizUserId')
				uni.request({
					method: 'POST',
					url: 'https://wlreaohs.xiaomy.net/common/biz/cloud/member/getIndividualMemberInfo',
					data: {
						bizUserId: bizUserId
					},
					header: { 'content-type': 'application/json' },
					success: (res) => {
						console.log(res)
						if(res.data.code == 0) {
							this.memberInfo = res.data.data.memberInfo
							console.log(this.memberInfo)
						} else {
							
						}
					},
					fail: (err) => {
						uni.hideLoading()
						console.log(err)
					}
				})
			},
			toRenZen() {
				var that = this;
				let bizUserId = uni.getStorageSync('bizUserId')
				if(this.memberInfo.isPhoneChecked) {
					if(that.params.name==''){
			            uni.showToast({
			                title: '请输入姓名',
			                icon: 'none'
			            });
					} else if(that.params.idCard==''){
			            uni.showToast({
			                title: '请输入身份证号',
			                icon: 'none'
			            });
					} else {
						uni.request({
							method: 'POST',
							url: 'https://qiancheng.mynatapp.cc/common/biz/cloud/member/setRealName',
							data: {
								bizUserId: bizUserId,
								name: that.params.name,
								identityNo: that.params.idCard
							},
							header: { 'content-type': 'application/json' },
							success: (ress) => {
								console.log(ress)
								if(ress.data.code == 0) {
									uni.showModal({
										title: '温馨提示',
										content: '实名认证成功~',
										showCancel: false,
										success: function (res) {
											if (res.confirm) {
												uni.switchTab({
													url: '/pages/me/me'
												})
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
								} else {
									uni.showModal({
										title: '温馨提示',
										content: `${ress.data.msg},实名认证失败~`,
										showCancel: false
									});
								}
							},
							fail: (err) => {
								uni.hideLoading()
								console.log(err)
							}
						})
					}
				} else {
					if(that.params.smsCode==''){
					            uni.showToast({
					                title: '请输入验证码',
					                icon: 'none'
					            });
							} else if(that.params.name==''){
					            uni.showToast({
					                title: '请输入姓名',
					                icon: 'none'
					            });
							} else if(that.params.idCard==''){
					            uni.showToast({
					                title: '请输入身份证号',
					                icon: 'none'
					            });
							} else {
								uni.request({
									method: 'POST',
									url: 'https://qiancheng.mynatapp.cc/common/biz/cloud/member/bindPhone',
									data: {
										bizUserId: bizUserId,
										phone: that.params.mobileNo,
										verificationCode: that.params.smsCode
									},
									header: { 'content-type': 'application/json' },
									success: (res) => {
										console.log(res)
										if(res.data.code == 0) {
											uni.showToast({
								                title: '手机号绑定成功',
								                icon: 'none'
								            });
											// 绑定成功
											uni.request({
												method: 'POST',
												url: 'https://qiancheng.mynatapp.cc/common/biz/cloud/member/setRealName',
												data: {
													bizUserId: bizUserId,
													name: that.params.name,
													identityNo: that.params.idCard
												},
												header: { 'content-type': 'application/json' },
												success: (ress) => {
													console.log(ress)
													if(ress.data.code == 0) {
														uni.showModal({
															title: '温馨提示',
															content: '实名认证成功~',
															showCancel: false,
															success: function (res) {
																if (res.confirm) {
																	uni.switchTab({
																		url: '/pages/me/me'
																	})
																} else if (res.cancel) {
																	console.log('用户点击取消');
																}
															}
														});
													} else {
														uni.showModal({
															title: '温馨提示',
															content: '实名认证失败~',
															showCancel: false
														});
													}
												},
												fail: (err) => {
													uni.hideLoading()
													console.log(err)
												}
											})
										} else {
											uni.showModal({
												title: '温馨提示',
												content: `${res.data.msg}`,
												showCancel: false
											});
										}
									},
									fail: (err) => {
										uni.hideLoading()
										console.log(err)
									}
								})
							}
				}
				
				
			},
			getCode() {
					var that = this;
					if(that.params.mobileNo==''){
			            uni.showToast({
			                title: '请输入手机号码',
			                icon: 'none'
			            });
					} else {
						uni.showLoading();
						that.disabled = true; //禁用点击
						let bizUserId = uni.getStorageSync('bizUserId')
						uni.request({
							method: 'POST',
							url: 'https://qiancheng.mynatapp.cc/common/biz/cloud/member/sendCaptcha',
							data: {
								bizUserId: bizUserId,
								phone: that.params.mobileNo,
								verificationCodeType: 9
							},
							header: { 'content-type': 'application/json' },
							success: (res) => {
								console.log(res)
								if(res.data.code == 0) {
									uni.hideLoading()
									uni.showToast({
				                       title: '获取验证码成功',
				                       icon: 'none'
					                });
									that.countdown = 60;
					                that.timestatus = true;
					                that.clear = setInterval(that.countDown,1000);
								} else {
									uni.hideLoading()
									uni.showToast({
				                       title: '获取验证码失败',
				                       icon: 'none'
					                });
									that.disabled = false; //获取失败开启点击
								}
							},
							fail: (err) => {
								uni.hideLoading()
								console.log(err)
								that.disabled = false;
							}
						})
			// 			sendSmsCode({
			// 				mobileNo: this.params.mobileNo
			// 			}).then(res => {
			// 				if(res.resultCode == 0) {
			// 					uni.hideLoading()
			// 					uni.showToast({
			//                        title: '获取验证码成功',
			//                        icon: 'none'
			// 	                });
			// 					that.countdown = 60;
			// 	                that.timestatus = true;
			// 	                that.clear = setInterval(that.countDown,1000);
			// 				} else {
			// 					uni.hideLoading()
			// 					uni.showToast({
			//                        title: '获取验证码失败',
			//                        icon: 'none'
			// 	                });
			// 					that.disabled = false; //获取失败开启点击
			// 				}
			// 			}).catch(err => {
			// 				uni.showModal({
			// 					title: '操作提示',
			// 					content: '系统错误!',
			// 					showCancel:false
			// 				})
			// 				that.disabled = false; //获取失败开启点击
			// 			})
					}
				},
				countDown() {
					var that = this;
					if(!that.countdown){
						that.disabled = false;
			            that.timestatus = false;
			            that.countdown = '获取验证码';
			            clearInterval(that.clear);
					} else {
						--that.countdown;
					}
				}
		}
	}
</script>

<style lang="scss" scoped>
	.login_box {
		width: 89%;
		position: absolute;
		top: 35rpx;
		left: 0;
		padding: 0 40rpx;
	}
	.uni-input {
		width: 440rpx;
		border-bottom: 1px solid rgba(0, 0, 0, 0.349019607843137);
		padding: 10rpx;
	}
	.hc_img {
		width: 30px;
		height: 30px;
		padding-bottom: 15rpx;
	}
	.register_yzm {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		border: 1px solid red;
	}
	.register_yzms {
		background-color: #477EDA;
		box-shadow: 5px 5px 5px rgba(242, 242, 242, 0.349019607843137);
		color: #FFFFFF;
		font-family: 'Arial Normal', 'Arial';
		font-weight: 400;
		font-size: 24rpx;
		border-radius: 10rpx;
		text-align: center;
		height: 70rpx;
		line-height: 75rpx;
		padding: 0 20rpx 0 20rpx;
	}
	.input_yzm {
		width: 290rpx;
		padding: 10rpx;
	}
	.yzm {
		width: 190rpx;
		height: 50rpx;
	}
	.txt1 {
		color: rgb(74, 74, 74);
		font-weight: 500;
		font-size: 28rpx;
	}
	.btn_pri {
		border-radius: 30rpx;
		margin-top: 60rpx;
		height: 70rpx;
		line-height: 70rpx;
		text-align: center;
		width: 90%;
		font-size: 26rpx;
		color: #FFFFFF;
		box-shadow: rgba(25, 94, 215, 0.4) 0px 4px 6px 1px;
	}
	.bg_img {
		width: 100%;
		height: 100%;
		overflow: hidden;
	}
	.txt_txt {
		color: rgb(74, 74, 74);
		font-weight: 500;
		font-size: 24rpx;
	}
	.account-txt {
		font-size: 24rpx;
	}
	.txt_box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		margin-top: 20rpx;
		padding: 0 30rpx;
	}
	.img_box {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.form_box {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-bottom: 30rpx;
	}
</style>
